package com.dong.zk;

import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.slf4j.Logger;

import java.io.IOException;

/**
 * @author: dzj
 * @date 2018/10/10-12:05
 */
public class BaseWatcher implements Watcher {
    public static final String zkServerPath = "10.0.109.142:2181";
    public static final Integer timeout=5000;
    private Logger logger;
    protected ZooKeeper zooKeeper =null;

    public ZooKeeper getZooKeeper() {
        return zooKeeper;
    }

    public BaseWatcher(Logger logger) {
        this.logger = logger;
    }

    public BaseWatcher(Logger logger, String path) {
        this.logger = logger;
        try {
            zooKeeper=new ZooKeeper(path,timeout,this);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void process(WatchedEvent watchedEvent) {
        logger.warn("接受到事件通知: "+watchedEvent);
    }
}
